package com.gitee.feizns.explore.data_structure.tree.bs.mid;

import java.util.HashSet;
import java.util.Set;

/**
 * 1261. 在受污染的二叉树中查找元素
 * @author feizns
 * @since 2020/3/17
 */
public class FindElements {

    public FindElements(TreeNode root) {
        create(root, 1);
    }

    Set<Integer> values = new HashSet<>();

    private void create(TreeNode node, int val) {
        if ( node != null ) {
            values.add(val);
            node.val = val;
            create(node.left, val * 2 + 1);
            create(node.right, val * 2 + 2);
        }
    }

    public boolean find(int target) {
        return values.contains(target);
    }

    public static void main(String[] args) {

    }

}
